<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Contract extends Model
{
	protected $table = 'contracts';

	protected $guarded  = ['referer'];

    /**
     * 应该被转换成原生类型的属性。
     *
     * @var array
     */
    protected $casts = [
        'contract'        => 'array',
        'invoice_receipt' => 'array',
    ];

	// 客户信息
    public function customer()
    {
        return $this->belongsTo('App\Models\Customer', 'cid');
    }

    // 订单
    public function order()
    {
        return $this->belongsTo('App\Models\Order', 'contract_no', 'contract_no');
    }

    // 续费
    public function renew()
    {
        return $this->belongsTo('App\Models\Renew', 'contract_no', 'contract_no');
    }

    // public function setContractNoAttribute($value)
    // {
    // 	if (!request('invoice_status')) {
    // 		$this->attributes['invoice_status'] = 0;
    // 	}

    // 	if (!request('invoice_receipt_status')) {
    // 		$this->attributes['invoice_receipt_status'] = 0;
    // 	}
    	
    //     $this->attributes['contract_no'] = trim($value);
    // }
}
